<?php

use yii\widgets\LinkPager;
use yii\helpers\Html;
use yii\helpers\Url;

?>
<div style="height:5px"></div>
<div class="btn-group" style="float: right;">
    <a href="<?=Url::toRoute(['role/addrole']);?>" class="btn btn-warning">添加角色</a>
</div>
<table id="dnd-example" cellspacing="0" class="table table-striped table-hover">
    <thead>
        <tr>
            <th>用户名</th>
            <th>所属角色</th>
            <th class="hidden-480">最后登录IP</th>
            <th><i class="icon-time bigger-110 hidden-480"></i>最后登录时间</th>
            <th class="hidden-480">真实姓名</th>
            <th>管理操作</th>
        </tr>
    </thead>
    <tbody>
        <?php
        $values=$dataProvider->getModels();
        foreach($values as $value):
            $role = $roles->getRolename($value->roleid);
        ?>
        
            <tr id="role_<?=$value->userid;?>">
                <td><?= Html::encode($value->username) ?></td>
                <td><?= Html::encode($role['rolename']) ?></td>
                <td><?= Html::encode($value->lastloginip) ?></td>
                <td><?= Html::encode($value->lastlogintime) ?></td>
                <td><?= Html::encode($value->realname) ?></td>
                <td>
                    <a href="<?= Url::toRoute(['admin/updateadmin', 'userid' => $value->userid,'roleid'=>$role['roleid']]);?>">
                        <button type="button" class="btn btn-success">编辑</button>
                    </a>
                    <a onclick="del(<?=$value->userid?>)">
                        <button type="button" class="btn btn-danger">删除</button>
                    </a>
                </td>
            </tr>
        <?php endforeach; ?>
    </tbody>
</table> 
<?php 
$pages=$dataProvider->getPagination();
echo LinkPager::widget([
    'pagination' => $pages,
    ]);

    ?>
<?php $this->beginBlock('opt') ?>

    //    删除栏目
    function del(userid){
    layer.confirm(
    '确定删除该管理员？',
    {icon: 5, title:'删除'},
    function(index){
    $.get("<?=Url::toRoute(['admin/deleteadmin'])?>", {userid:userid},
    function(data){
    if(data.status == 1){
    $("#role_"+userid).hide();
}
layer.msg(data.msg);
});
layer.close(index);
});
}
<?php $this->endBlock() ?>
<?php $this->registerJs($this->blocks['opt'], \yii\web\View::POS_END); ?>